<template>
  <div class="user-wrapper">
    <div class="content-box">
      <a
        href="https://pro.loacg.com/docs/getting-started"
        target="_blank"
      >
        <span class="action">
          <p-icon type="question-circle-o" style="font-size: 18px"/>
        </span>
      </a>
      <notice-icon class="action" />
      <p-dropdown>
        <span class="action ant-dropdown-link user-dropdown-menu">
          <p-avatar
            class="avatar"
            size="small"
            :src="avatar"
          />
          <span>{{ nickname }}</span>
        </span>
        <p-menu
          slot="overlay"
          class="user-dropdown-menu-wrapper"
        >
          <p-menu-item key="0">
            <router-link :to="{ name: 'center' }">
              <p-icon type="user" />
              <span>个人中心</span>
            </router-link>
          </p-menu-item>
          <p-menu-item key="2" @click="systemSetting">
              <p-icon type="tool" />
              <span>系统设置</span>
          </p-menu-item>
          <p-menu-item key="1">
            <router-link :to="{ name: 'settings' }">
              <p-icon type="setting" />
              <span>账户设置</span>
            </router-link>
          </p-menu-item>
          <p-menu-divider />
          <p-menu-item key="3">
            <a
              href="javascript:;"
              @click="handleLogout"
            >
              <p-icon type="logout" />
              <span>退出登录</span>
            </a>
          </p-menu-item>
        </p-menu>
      </p-dropdown>
    </div>
    <setting-drawer ref="settingDrawer" :closable="true" title="系统设置"></setting-drawer>
  </div>
</template>

<script>
 import SettingDrawer from "@/components/SettingDrawer/SettingDrawer";
import NoticeIcon from '@/components/NoticeIcon'
import { mapActions, mapGetters } from 'vuex'

export default {
  name: 'UserMenu',
  components: {
    NoticeIcon,
    SettingDrawer
  },
  computed: {
    ...mapGetters(['nickname', 'avatar'])

  },
  methods: {
    ...mapActions(['Logout']),
    handleLogout () {
      this.$confirm({
        title: '提示',
        content: '真的要注销登录吗 ?',
        onOk: () => {
          return this.Logout({}).then(() => {
            setTimeout(() => {
              window.location.reload()
            }, 16)
          }).catch(err => {
            this.$message.error({
              title: '错误',
              description: err.message
            })
          })
        },
        onCancel () {
        }
      })
    },
     systemSetting(){
        this.$refs.settingDrawer.showDrawer()
      },
  }
}
</script>
